﻿Public Class Quiz
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub rb_q1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles rb_q1.SelectedIndexChanged
        If rb_q1.SelectedValue = "*" Then
            lbl_q1ans.Text = "Correct!"
        Else
            lbl_q1ans.Text = "Sorry, that's incorrect"
        End If
    End Sub


    Protected Sub rbl_q2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles rbl_q2.SelectedIndexChanged
        If rbl_q2.SelectedValue = "*" Then
            lbl_q2ans.Text = "That's correct!"
        Else
            lbl_q2ans.Text = "Sadly, that is incorrect"
        End If
    End Sub

    Protected Sub btn_q3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_q3.Click
        If isRight(cbl_q3) Then
            lbl_q3cities.Text = "Well done, that's correct!"
        Else
            lbl_q3cities.Text = "Sorry, that's incorrect."
        End If
    End Sub

    Function getSelectedItems(ByVal myCheckBoxList As CheckBoxList)
        Dim s As String = ""
        For i = 0 To myCheckBoxList.Items.Count - 1
            If myCheckBoxList.Items(i).Selected = True Then
                s = s & myCheckBoxList.Items(i).Text & "<br/>"
            End If
        Next
        Return s
    End Function

    Function isRight(ByVal myCheckBoxList As CheckBoxList)
        For i = 0 To myCheckBoxList.Items.Count - 1
            'Check if user has not chosen correct item
            If myCheckBoxList.Items(i).Value = "*" And myCheckBoxList.Items(i).Selected = False Then
                Return False
            End If
            'Check if user has chosen an incorrect item
            If myCheckBoxList.Items(i).Value <> "*" And myCheckBoxList.Items(i).Selected = True Then
                Return False
            End If
        Next
        Return True
    End Function

    Protected Sub btn_qSimpsons_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_qSimpsons.Click
        If isRight(cbl_Simpsons) Then
            lbl_Simpsons.Text = "Well done Simpsons fan, that's correct."
        Else
            lbl_Simpsons.Text = "Sorry, that's not quite right."
        End If
    End Sub
End Class